﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

    class BinToHex
    {
        static void Main(string[] args)
        {
            string bin = "000111110100";

            int rest = bin.Length % 4;
            if (rest != 0)
            {
                bin = new string('0', 4 - rest) + bin; //pad the length out to by divideable by 4
            }

            string output = "";

            for (int i = 0; i <= bin.Length - 4; i += 4)
            {
                output += string.Format("{0:X}", Convert.ToByte(bin.Substring(i, 4), 2));
            }
            Console.Write(output);
            Console.WriteLine();
        }
    }

